/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.base.entity.catalog;

import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonBackReference;

import com.thinkgem.jeesite.common.persistence.TreeEntity;

/**
 * 基础管理_目录信息生成Entity
 * @author 呆子
 * @version 2020-02-21
 */
public class BaseCatalog extends TreeEntity<BaseCatalog> {
	
	private static final long serialVersionUID = 1L;
	private String name;		// 名称
	private Integer sort;		// 排序
	private BaseCatalog parent;		// 父ID
	private String parentIds;		// 所有父ID
	
	public BaseCatalog() {
		super();
	}

	public BaseCatalog(String id){
		super(id);
	}

	@Length(min=1, max=255, message="名称长度必须介于 1 和 255 之间")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@NotNull(message="排序不能为空")
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}
	
	@JsonBackReference
	@NotNull(message="父ID不能为空")
	public BaseCatalog getParent() {
		return parent;
	}

	public void setParent(BaseCatalog parent) {
		this.parent = parent;
	}
	
	@Length(min=1, max=1000, message="所有父ID长度必须介于 1 和 1000 之间")
	public String getParentIds() {
		return parentIds;
	}

	public void setParentIds(String parentIds) {
		this.parentIds = parentIds;
	}
	
	public String getParentId() {
		return parent != null && parent.getId() != null ? parent.getId() : "0";
	}
}